package com.baixun.gascommon.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * knife4j配置文档
 */

@Configuration
@EnableSwagger2
@EnableKnife4j
public class Knife4jConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                //指定页面信息
                .apiInfo(apiInfo())
                //创建选择器
                .select()
                //指定扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.baixun.gasadmin.controller"))
                //只扫描users开头路径
                //.paths(PathSelectors.ant("/users/**"))
                //所有这个包涉及到的路径都被扫描
                .paths(PathSelectors.any())
                //执行创建
                .build();

    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("上海燃气可视化驾驶舱项目")
                .description("上海燃气可视化驾驶舱项目")
                .version("1.0.0")
                .build();
    }

    /**
     * 安全模式，这里指定token通过Authorization头请求头传递
     */
    private List<SecurityScheme> securitySchemes() {
        List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
        apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
        return apiKeyList;
    }



}
